
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 03/16/2012 12:19:18
-- Generated from EDMX file: C:\Users\jose.gonzalez\documents\visual studio 2010\Projects\EntityFrameWork\EntityFrameWork\Clientes.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [RepairsDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_VehiculoRepair]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Repairs] DROP CONSTRAINT [FK_VehiculoRepair];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Vehiculos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Vehiculos];
GO
IF OBJECT_ID(N'[dbo].[Repairs]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Repairs];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Vehiculos'
CREATE TABLE [dbo].[Vehiculos] (
    [id] int IDENTITY(1,1) NOT NULL,
    [Make] nvarchar(max)  NOT NULL,
    [Model] nvarchar(max)  NOT NULL,
    [GarageAddress_Line1] nvarchar(max)  NOT NULL,
    [GarageAddress_Line2] nvarchar(max)  NOT NULL,
    [GarageAddress_City] nvarchar(max)  NOT NULL,
    [GarageAddress_State] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Repairs'
CREATE TABLE [dbo].[Repairs] (
    [id] int IDENTITY(1,1) NOT NULL,
    [VehicleId] int  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Cost] decimal(18,0)  NOT NULL
);
GO

-- Creating table 'Vehiculos_Car'
CREATE TABLE [dbo].[Vehiculos_Car] (
    [Year] smallint  NOT NULL,
    [id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [id] in table 'Vehiculos'
ALTER TABLE [dbo].[Vehiculos]
ADD CONSTRAINT [PK_Vehiculos]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'Repairs'
ALTER TABLE [dbo].[Repairs]
ADD CONSTRAINT [PK_Repairs]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'Vehiculos_Car'
ALTER TABLE [dbo].[Vehiculos_Car]
ADD CONSTRAINT [PK_Vehiculos_Car]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [VehicleId] in table 'Repairs'
ALTER TABLE [dbo].[Repairs]
ADD CONSTRAINT [FK_VehiculoRepair]
    FOREIGN KEY ([VehicleId])
    REFERENCES [dbo].[Vehiculos]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VehiculoRepair'
CREATE INDEX [IX_FK_VehiculoRepair]
ON [dbo].[Repairs]
    ([VehicleId]);
GO

-- Creating foreign key on [id] in table 'Vehiculos_Car'
ALTER TABLE [dbo].[Vehiculos_Car]
ADD CONSTRAINT [FK_Car_inherits_Vehiculo]
    FOREIGN KEY ([id])
    REFERENCES [dbo].[Vehiculos]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------